Skip to content

Add missing endpoints (/compatibility, /mode) to SchemaRegistryClient #2024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

fangnx
Copy link
Member

@fangnx fangnx commented Aug 18, 2025

What

Add the missing endpoints and update the existing ones to SR client, for /compatibility and /mode endpoints.

Checklist

  • Contains customer facing changes? Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?
    • If not, please explain why it is not required

References

JIRA: https://confluentinc.atlassian.net/browse/DGS-21591

Test & Review

Open questions / Follow-ups

@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

@fangnx fangnx marked this pull request as ready for review August 18, 2025 20:37
@Copilot Copilot AI review requested due to automatic review settings August 18, 2025 20:37
@fangnx fangnx requested review from MSeal and a team as code owners August 18, 2025 20:37
@fangnx fangnx changed the base branch from master to sr-endpoints-add-1 August 18, 2025 20:38
Copilot

This comment was marked as outdated.

@sonarqube-confluent

This comment has been minimized.

@sonarqube-confluent

This comment has been minimized.

@fangnx fangnx requested a review from rayokota August 18, 2025 21:08
@sonarqube-confluent

This comment has been minimized.

)
return response['is_compatible'] # TODO: should it return entire response (including error messages)?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe return a tuple [bool, Response] so it's easy to have a simple response vs a parsing the complex object? But I think this should probably return the full response by itself with a reference in the docstring to the is_compatible as a likely attribute for consumption.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is this would be a breaking change, although in this case I think it might be necessary to just make the change (or add a separate method and mark this one as @deprecated): not sure how customers usually interact with test_compatibility, but intuitively I think the "messages" field for test_compatibility is important to include
cc @rayokota if you have any thoughts on this :)

`GET Global Mode API Reference <https://docs.confluent.io/current/schema-registry/develop/api.html#get--mode>`_
""" # noqa: E501
result = self._rest_client.get('mode')
return result['mode']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a debug log here with the result if you're not returning the full payload so the contents aren't lost (or maybe generally have a logging debug level option for all rest requests made to SR service)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, mode is the only field in the JSON returned from this API

@sonarqube-confluent

This comment has been minimized.

1 similar comment
@sonarqube-confluent

This comment has been minimized.

Base automatically changed from sr-endpoints-add-1 to master August 20, 2025 14:19
@sonarqube-confluent

This comment has been minimized.

1 similar comment
@sonarqube-confluent

This comment has been minimized.

@sonarqube-confluent

This comment has been minimized.

@fangnx fangnx requested a review from Copilot August 21, 2025 20:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds missing endpoints for /compatibility and /mode operations to the Schema Registry Client, expanding the client's API coverage to match the complete Schema Registry REST API.

Key changes include:

  • Added new mode management endpoints for global and subject-level mode operations
  • Enhanced compatibility testing with new all-versions endpoint and query parameters
  • Added configuration deletion endpoint and contexts listing endpoint

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
tests/schema_registry/conftest.py Updated mock server to support new endpoints with proper regex patterns and callback handlers
tests/schema_registry/_sync/test_api_client.py Added comprehensive test coverage for all new sync client methods
tests/schema_registry/_async/test_api_client.py Added comprehensive test coverage for all new async client methods
src/confluent_kafka/schema_registry/_sync/schema_registry_client.py Implemented new endpoint methods and enhanced existing compatibility testing
src/confluent_kafka/schema_registry/_async/schema_registry_client.py Implemented new endpoint methods and enhanced existing compatibility testing
Comments suppressed due to low confidence (1)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -97,10 +97,12 @@
+--------+-------------------------------------------------+-------+------------------------------+
| DELETE | /subjects/notfound/versions/422 | 42202 | Invalid version |
+--------+-------------------------------------------------+-------+------------------------------+
| GET | /config/notconfig | 40401 | Subject not found |
| GET | /config/notfound | 40401 | Subject not found |
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The table entry for GET /config/notfound shows error code 40401 but the actual mock implementation on line 234 returns the same error code. Consider clarifying if this path should represent a different test case since 'notfound' is used as a trigger for error scenarios.

Suggested change
| GET | /config/notfound | 40401 | Subject not found |
| GET | /config/notfound | 40401 | Subject not found (uses 'notfound' trigger) |

Copilot uses AI. Check for mistakes.

COUNTER['GET'][request.url.path] += 1
return Response(200, json=json.loads(_load_avsc(SCHEMA)))
return Response(200, json=[1, 2])


def get_subject_version_referenced_by_callback(request, route):
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is defined twice in the same file (lines 410 and 415), which will cause the second definition to override the first. This could lead to unexpected behavior in tests.

Copilot uses AI. Check for mistakes.

def put_global_mode_callback(request, route):
COUNTER['PUT'][request.url.path] += 1
body = json.loads(request.content.decode('utf-8'))
print(body)
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statement should be removed from production code. Consider using logging instead if debugging output is needed.

Suggested change
print(body)
logger.debug(body)

Copilot uses AI. Check for mistakes.

@@ -889,6 +888,13 @@ def get_subjects(
"""
Lists all subjects registered with the Schema Registry.

Args:
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Args section in docstring. The Args section appears twice (lines 891-897 and 898-904), which creates confusing documentation.

Copilot uses AI. Check for mistakes.

def test_compatibility_all_versions(
self, subject_name: str, schema: 'Schema',
normalize: bool = False, verbose: bool = False
) -> bool:
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] TODO comment suggests uncertainty about the API design. Consider resolving this before merging or creating a follow-up ticket to address whether detailed error messages should be returned.

Copilot uses AI. Check for mistakes.

@@ -889,6 +888,13 @@ async def get_subjects(
"""
Lists all subjects registered with the Schema Registry.

Args:
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Args section in docstring. The Args section appears twice (lines 891-897 and 898-904), which creates confusing documentation.

Copilot uses AI. Check for mistakes.

)
return response['is_compatible'] # TODO: should it return entire response (including error messages)?
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] TODO comment suggests uncertainty about the API design. Consider resolving this before merging or creating a follow-up ticket to address whether detailed error messages should be returned.

Suggested change
return response['is_compatible'] # TODO: should it return entire response (including error messages)?
return response

Copilot uses AI. Check for mistakes.

subject_name (str): Subject of the schema versions against which compatibility is to be tested.
schema (Schema): Schema instance.
normalize (bool): Whether to normalize the input schema.
verbose (bool): Wehther to return detailed error messages.
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in parameter documentation: 'Wehther' should be 'Whether'.

Suggested change
verbose (bool): Wehther to return detailed error messages.
verbose (bool): Whether to return detailed error messages.

Copilot uses AI. Check for mistakes.

),
body=request,
)
return response['is_compatible'] # TODO: should it return entire response (including error messages)?
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Duplicate TODO comment with same uncertainty about API design. This appears in multiple methods suggesting a broader design decision is needed.

Suggested change
return response['is_compatible'] # TODO: should it return entire response (including error messages)?
return response

Copilot uses AI. Check for mistakes.


async def get_global_mode(self) -> str:
"""
Get the current mode for Schema Reigstry at a global level.
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in docstring: 'Reigstry' should be 'Registry'.

Suggested change
Get the current mode for Schema Reigstry at a global level.
Get the current mode for Schema Registry at a global level.

Copilot uses AI. Check for mistakes.

@sonarqube-confluent
Copy link

Passed

Analysis Details

7 Issues

  • Bug 0 Bugs
  • Vulnerability 0 Vulnerabilities
  • Code Smell 7 Code Smells

Coverage and Duplications

  • Coverage 100.00% Coverage (66.60% Estimated after merge)
  • Duplications No duplication information (5.60% Estimated after merge)

Project ID: confluent-kafka-python

View in SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants